package br.com.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.dao.ItemDao;
import br.com.model.Item;

@FacesConverter(forClass=Item.class, value="itemConverter")
public class ItemConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		Item item = new Item();
		item = ItemDao.pesquPorId(Integer.parseInt(value));
		return item;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		 if(value != null && value instanceof Item ){
			 String retorno = String.valueOf(((Item)value).getIdItem());
			 return retorno;
		 }
		 return "";
	}

}
